package com.kerbores.utils.db.file;

import java.io.File;
import java.util.Date;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.lang.Times;
import org.nutz.lang.random.R;

import com.kerbores.utils.db.data.Entity;
import com.kerbores.utils.file.Images;

@Deprecated
public class ImageFile extends Entity {

	/**
	 * 文件名
	 */
	@Column("i_nema")
	private String name;

	/**
	 * 文件数据
	 */
	@Column("i_data")
	private String data;

	/**
	 * 文件创建时间
	 */
	@Column("i_create_time")
	private Date createTime;

	/**
	 * 文件最后修改时间
	 */
	@Column("i_last_modify")
	private Date lastModify;
	/**
	 * 文件长度
	 */
	@Column("i_length")
	private long length;
	/**
	 * 文件所有者
	 */
	@Column("i_owner")
	private String owner;
	/**
	 * 文件类型
	 */
	@Column("i_type")
	private String type;
	/**
	 * 文件唯一标识
	 */
	@Column("i_uuid")
	private String uuid = R.UU16();

	public ImageFile() {
		super();
	}

	public ImageFile(File file) {
		super();
		this.length = file.length();
		this.lastModify = Times.D(file.lastModified());
		this.createTime = Times.now();
		this.name = file.getName();
		this.data = Images.GetImageStr(file);
		this.type = name.substring(name.lastIndexOf(".") + 1, name.length());
	}

	/**
	 * 
	 * @param path
	 *            图片保存的临时目录
	 * @return
	 */
	public File getFile(String path) {
		return Images.GenerateImage(data, new File(path), type);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getLastModify() {
		return lastModify;
	}

	public void setLastModify(Date lastModify) {
		this.lastModify = lastModify;
	}

	public long getLength() {
		return length;
	}

	public void setLength(long length) {
		this.length = length;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

}
